import Vue from 'vue'
import VueRouter from 'vue-router'
// 引入home文件
import Home from '../views/home/Home.vue'

Vue.use(VueRouter)

//获取原型对象上的replace函数
const originalReplace = VueRouter.prototype.replace
//修改原型对象中的replace方法
VueRouter.prototype.replace = function push(location) {
	return originalReplace.call(this, location).catch(err => err)
}
//获取原型对象上的replace函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}


const routes = [{
		path: '/',
		name: 'home',
		component: Home,
		redirect: '/movie/hot', //重定向到正在热映页面
		children: [
			// 电影页面
			{
				path: 'movie',
				name: 'movie',
				component: () => import('@/views/home/Movie.vue'),
				children: [
					// 正在热映
					{
						path: 'hot',
						name: 'hot',
						component: () => import("@/views/home/movie/Hotshowing.vue")
					},
					// 即将上映
					{
						path: 'soon',
						name: 'soon',
						component: () => import("@/views/home/movie/Comingsoon.vue")
					}
				]

			},
			// 影院页面
			{
				path: "cinema",
				name: 'cinema',
				component: () => import('@/views/home/Cinema.vue')
			}
		]
	},
	/* 电影具体页面*/
	{
		path: '/film/:rou/:id',
		name: 'film',
		component: () => import('@/views/nohome/Film.vue')
	},
	/* 影院具体页面*/
	{
		path: "/cfilm/:id",
		name: 'cfilm',
		component: () => import('@/views/nohome/cFilm.vue'),
		children: [
			/* 影院排场子路由*/
			{
				path: ':filmId/:date',
				name: 'cpfilm',
				component: () => import('@/views/nohome/cpFilm.vue'),
				beforeEnter: (to, from, next) => {
					console.log(to, "单独守卫")
					next()
				}
			}
		]
	},
	// 城市页面
	{
		path: '/city',
		name: 'city',
		component: () => import('@/views/nohome/City.vue')
	}
	// {
	//   path: '/about',
	//   name: 'about',
	//   // route level code-splitting
	//   // this generates a separate chunk (about.[hash].js) for this route
	//   // which is lazy-loaded when the route is visited.
	//   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
	// }
]


const router = new VueRouter({
	routes
})

/* 全局守卫 */
router.beforeEach((to, from, next) => {
	next()
})

export default router
